﻿using Developer.Core.FrameWork.GlobalVar;
using Developer.Core.FrameWork.HelpFile;
using Developer.Core.FrameWork.RegisterCenter.Consul;
using Developer.Core.FrameWork.RegisterCenter.Options;
using Developer.Core.FrameWork.RegisterCenter.Service;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;

namespace Developer.Core.FrameWork.RegisterCenter.Extensions
{
    /// <summary>
    /// 服务发现扩展
    /// </summary>
    public static class ServiceDiscoveryCollectionExtensions
    {
        public static IServiceCollection AddServiceDiscovery(this IServiceCollection services)
        {
            AddServiceDiscovery(services, option => { });

            return services;
        }

        public static IServiceCollection AddServiceDiscovery(this IServiceCollection services,Action<ServiceDiscoveryOptions> options)
        {
            // 0、是否开启Consul服务发现
            if (!GlobalVars.ConsulDiscovery)
                return services;

            services.Configure<ServiceDiscoveryOptions>(options);

            services.AddSingleton<IServiceDiscovery, ConsulServiceDiscovery>();

            return services;
        }
    }
}
